/*
	The MIT License

	Copyright (c) 2008 IFMO/GameDev Studio

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/
// gui_controls.h - 

#pragma once


#define		BORDER_SOLID	"ui/border_solid.tga"
#define		BORDER_OUTLINE	"ui/border_outline.tga"



class EGUIWindow : public EGUIFrame {
	public:
							EGUIWindow		( EGUIManager *fm, const char *name, float x, float y, float w, float h );
		virtual				~EGUIWindow		( void );
						
		virtual bool		IsVisible		( void ) const;
		virtual void		FMProcess		( float delta, float time );
		virtual void		FMPaint			( void );
		virtual void		FMMouseClick	( uint button, float x, float y );
		
		virtual uiRect_s	GetClientRect	( void ) const;
		
	protected:
		static	void	SetText_f			( EGUIWindow *self, int argc, char **argv );
		static	void	VAlign				( EGUIWindow *self, int argc, char **argv );
		static	void	HAlign				( EGUIWindow *self, int argc, char **argv );
		void			ComputeClientRect	( void );
		
		string	text;
	};	


class EGUIButton : public EGUIFrame {
	public:
							EGUIButton		( EGUIManager *fm, const char *name, float x, float y, float w, float h );
		virtual				~EGUIButton		( void );
						
		virtual void		FMPaint			( void );
		virtual void		FMMouseClick	( uint button, float x, float y );
		virtual void		FMMouseDown		( uint button, float x, float y );
		virtual void		FMMouseUp		( uint button, float x, float y );
		virtual void		FMMouseIn		( void );
		virtual void		FMMouseOut		( void );
		virtual void		FMProcess		( float delta, float time );
		
	protected:
		static	void		SetText_f		( EGUIButton *self, int argc, char **argv );
		static	void		SetCommand_f	( EGUIButton *self, int argc, char **argv );
		
		bool	btn_down;
		float	highlight;
		string	text;
		string	command;
	};	
	

class EEditor {
	public:
					EEditor			( void );
					~EEditor		( void );
					
		void		InputChar		( uint code );
		void		Backspace		( void );
		void		Delete			( void );
		void		MoveCursor		( int step );
		const char	*GetText		( void ) const { return text.c_str(); }
		void		SetText			( const char *text );
		int			GetCursorPos	( void ) const { return cursor_pos; }
	protected:
		void		BoundCursor		( void );
		string	text;
		int		cursor_pos;
	};


//class EGUIEditBox : public EGUIFrame {
//	public:
//							EGUIEditBox			( EGUIManager *fm, const char *name, float x, float y, float w, float h );
//							~EGUIEditBox		( void );
//		virtual void		FMPaint				( void );
//		virtual void		FMKeyPress			( uint code );
//		virtual void		FMKeyDown			( uint code );
//		virtual void		FMProcess			( float delta, float time );
//		virtual void		FMCtrlReadConfig	( void );
//		virtual void		FMCtrlWriteConfig	( void );
//		
//	protected:
//		static void			SetVar_f		( EGUIEditBox *self, int argc, char **argv );
//		EEditor	editor;
//		float	highlight;
//		float	cursor_time;
//		IVar	*var;
//	};


class EGUIControl : public EGUIFrame {
	public:
							EGUIControl			( EGUIManager *fm, const char *name, float x, float y, float w, float h );
		virtual				~EGUIControl		( void );
		virtual void		FMPaint				( void );
		virtual void		FMProcess			( float delta, float time );
		virtual void		FMCtrlReadConfig	( void );
		virtual void		FMCtrlWriteConfig	( void );
		
	protected:
		uiRect_s			GetTextRect		( void );
		uiRect_s			GetCtrlRect		( void );
		static void			SetVar_f		( EGUIControl *self, int argc, char **argv );
		static void			SetText_f		( EGUIControl *self, int argc, char **argv );
		float	highlight;
		float	flicker_time;
		string	text;
		string	value;
		IVar	*var;
	};


class EGUIEditBox : public EGUIControl {
	public:
							EGUIEditBox			( EGUIManager *fm, const char *name, float x, float y, float w, float h );
		virtual				~EGUIEditBox		( void );
		virtual void		FMPaint				( void );
		virtual void		FMKeyPress			( uint code );
		virtual void		FMKeyDown			( uint code );
	protected:
	};


class EGUICheckBox : public EGUIControl {
	public:
							EGUICheckBox		( EGUIManager *fm, const char *name, float x, float y, float w, float h );
							~EGUICheckBox		( void );				
		virtual void		FMPaint				( void );
		virtual void		FMMouseClick		( uint button, float x, float y ); 
	protected:
	};


class EGUISlider : public EGUIControl {
	public:
							EGUISlider			( EGUIManager *fm, const char *name, float x, float y, float w, float h );
							~EGUISlider			( void );				
		virtual void		FMPaint				( void );
		virtual void		FMMouseClick		( uint button, float x, float y ); 
		virtual void		FMKeyDown			( uint code );
		virtual void		FMProcess			( float delta, float time );
	protected:
		static void			SetMinMax_f		( EGUISlider *self, int argc, char **argv );
		EGUIButton	*button_left;
		EGUIButton	*button_right;
		float	prev_val;
		float	min_val;
		float	max_val;
		float	step;
	};















